/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-04-04     金鹏       the first version
 */

#include "cmn_helper.h"
extern short len;
extern int cm_switch;               /* 网络状态*/
short voice_lock = 0;               /* 语音锁*/
short group = 1;                    /* 组别*/
short warn_flag = 0;                /* 求助标志*/
/*
 * command_deal
 * @Param NULL
 *
 * Change Logs:
 * Date         Author       Notes
 * 2025-4-4      金鹏        命令处理
 */
void command_deal(char *ret)
{
    char *name;
    char *name1;
    static unsigned char buff[100];
    static short bz = 0;

    /* 当WIFI开关打开时*/
    if(cm_switch == 0){
        name = "WIFI";
        name1 = "4G";
    }/* 当4G开关打开时*/
    else{
        name = "4G";
        name1 = "WIFI";
    }

    switch(*(ret+1)){
        case 'w':
            rt_kprintf("%s -> warn!!\n",name);
            SYN6288_Say_UTF8("警报 这里有危险");

            break;
        case 'o':
            if(*(ret+2) == '1'){
                rt_kprintf("%s -> ok!!\n",name);
                SYN6288_Say_UTF8("已经接收到求助");
            }
            break;
        default:
        {
            /* 中文指令解析*/
            for(int i=0;ret[i]!='}';i++){
                if(ret[i] != '@'){
                    buff[bz++] = ret[i];
                }

                if(ret[i] == '!'){
                    char *p;
                    buff[bz] = '\0';
                    if(p = rt_strstr(buff,"g")){                    /* 判断是否同组*/
                        if(*(p+1) != (group+'0')){
                            bz = 0;
                            break;
                        }
                    }
                    else if(p = rt_strstr(buff,"u")){               /* 判断是否同用户*/
                        if(*(p+1) != '1'){
                            bz = 0;
                            break;
                        }
                    }

                    SYN6288_Say_UTF8(buff+2);
                    /* 上锁，防止语音干扰*/
                    voice_lock = 1;
                    rt_kprintf("voice lock\n");
                    rt_timer_start(voice_timer);
                    bz = 0;
                }
            }

            //rt_kprintf("\n");
        }
    }
}
